package model

import (
	"smart-health-platforms/config"
	"time"
)

type RecentEvents struct {
	Id        uint32    `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    int32     `gorm:"column:user_id;type:int;default:NULL;" json:"user_id"`
	OrderOn   string    `gorm:"column:order_on;type:varchar(255);default:NULL;" json:"order_on"`
	Type      int32     `gorm:"column:type;type:int;comment:1-秒杀2-拼团3-砍价;default:NULL;" json:"type"` // 1-秒杀2-拼团3-砍价
	GoodId    int32     `gorm:"column:good_id;type:int;default:NULL;" json:"good_id"`
	CreatedAt time.Time `gorm:"column:created_at;type:datetime(3);default:CURRENT_TIMESTAMP(3);" json:"created_at"`
}

func (r *RecentEvents) TableName() string {
	return "recent_events"
}
func (r *RecentEvents) AddRecentEvents() error {
	return config.DB.Create(&r).Error
}
func (r *RecentEvents) ListRecentEvents() (list []RecentEvents, err error) {
	err = config.DB.Where("user_id = ?", r.UserId).Find(&list).Error
	return
}
